package com.googlecode.yoohoo.xmppcore.protocol.stanza.error;

import junit.framework.Assert;

import org.junit.Test;

import com.googlecode.yoohoo.xmppcore.protocol.stanza.StanzaKind;

public class StanzaErrorTest {
	@Test
	public void toXml() {
		String xml =
			"<iq type='error' id='some-id'>" +
				"<error type='modify'>" +
					"<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
					"<too-many-parameters xmlns='application-ns'/>" +
				"</error>" +
			"</iq>";

		
		BadRequest badRequest = new BadRequest();
		badRequest.setStanzaKind(StanzaKind.IQ);
		badRequest.setId("some-id");
		badRequest.setApplicationSpecificCondition(new SimpleApplicationSpecificCondition(
				"too-many-parameters", "application-ns"));
		
		Assert.assertEquals(xml, badRequest.toXml());
	}
	
	@Test
	public void attachSenderXml() {
		String senderXml = 
			"<iq type='set' to='shakespeare.lit' id='some-id'>" +
				"<query xmlns='jabber:iq:register'>" +
					"<username>bill</username>" +
					"<password>newpass</password>" +
					"<confirm-password>newpass</confirm-password>" +
				"</query>" +
			"</iq>";
		
		String errorXml =
			"<iq type='error' id='some-id'>" +
				"<error type='modify'>" +
					"<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
					"<too-many-parameters xmlns='application-ns'/>" +
				"</error>" +
			"</iq>";
		
		BadRequest badRequest = new BadRequest();
		badRequest.setApplicationSpecificCondition(new SimpleApplicationSpecificCondition(
				"too-many-parameters", "application-ns"));
		badRequest.setSenderXml(senderXml);
		
		Assert.assertEquals(errorXml, badRequest.toXml());
	}
}
